Stored Procedures [dbo].[asi_GetSalesHistoryResponseStart]
Properties
PropertyValue
ANSI Nulls OnYes
Quoted Identifier OnYes
Parameters
NameData TypeMax Length (Bytes)Direction
@userKeyuniqueidentifier16
@rangeBegindatetime8Out
@rangeEnddatetime8Out
SQL Script
/****** Object:  Stored Procedure dbo.asi_GetSalesHistoryResponseStart    ******/

CREATE       PROCEDURE [dbo].[asi_GetSalesHistoryResponseStart]

@userKey     uniqueidentifier,
@rangeBegin     datetime OUTPUT,
@rangeEnd     datetime OUTPUT

AS

DECLARE @newGuid             uniqueidentifier
DECLARE @EveryoneFullControlAccessKey     uniqueidentifier
DECLARE @now                 datetime
DECLARE @defaultDate            datetime

SET @defaultDate = '1/1/1980'
SET @rangeBegin = @defaultDate
SET @rangeEnd = @defaultDate

BEGIN TRAN

-- Get the ending value
SELECT    @rangeEnd =  ISNULL(MAX(CreatedOn), @defaultDate)
FROM    SalesHistory

-- Check to make sure the counter exists - create it if not
IF NOT EXISTS(SELECT 1 FROM SystemConfig WHERE ParameterName='SalesHistoryResponseRangeStart')
BEGIN
    SELECT @newGuid = newid()
    SELECT @now = getdate()

    INSERT SystemConfig (SystemConfigKey, ParameterName, ParameterValue, [Description],
           OrganizationKey, SystemEntityKey, CreatedByUserKey, CreatedOn, UpdatedByUserKey, UpdatedOn)
    VALUES(    @newGuid,
        'SalesHistoryResponseRangeStart',
        CAST(@rangeEnd As nvarchar(100)),
        'Ending point in the SalesHistory table already processed by response acquisition.',
        '00000000-0000-0000-0000-000000000000',
        NULL,
        @userKey,
        @now,
        @userKey,
        @now)
END

-- Get the beginning value
SELECT    @rangeBegin = ISNULL(CAST(ParameterValue AS datetime), @defaultDate)
  FROM    SystemConfig
WHERE    ParameterName = 'SalesHistoryResponseRangeStart'

-- Set the ending value
UPDATE    SystemConfig
   SET    ParameterValue = CAST(@rangeEnd AS nvarchar(100))
WHERE    ParameterName = 'SalesHistoryResponseRangeStart'

COMMIT TRAN

GO
Uses